﻿<TextBox x:Class="AllProgrammic.WPF.DataForm.Controls.WatermarkedTextBox"    
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
    xmlns:local="clr-namespace:AllProgrammic.WPF.DataForm.Controls">
    <TextBox.Resources>
        <LinearGradientBrush x:Key="TextBoxBorder" EndPoint="0,20" StartPoint="0,0" MappingMode="Absolute">
            <GradientStop Color="#ABADB3" Offset="0.05"/>
            <GradientStop Color="#E2E3EA" Offset="0.07"/>
            <GradientStop Color="#E3E9EF" Offset="1"/>
        </LinearGradientBrush>
        <SolidColorBrush x:Key="WatermarkBrush" Color="#FFAAAAAA"/>
    </TextBox.Resources>
    <TextBox.Style>
        <Style TargetType="{x:Type local:WatermarkedTextBox}">
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
            <Setter Property="BorderBrush" Value="{StaticResource TextBoxBorder}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Padding" Value="1"/>
            <Setter Property="AllowDrop" Value="true"/>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate 
                TargetType="{x:Type local:WatermarkedTextBox}">
                        <Microsoft_Windows_Themes:ListBoxChrome x:Name="Bd" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" RenderFocused="{TemplateBinding IsKeyboardFocusWithin}" RenderMouseOver="{TemplateBinding IsMouseOver}">
                            <Grid>
                            <ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            <ContentControl
                                            x:Name="PART_HelpTextElement"
                                            Visibility="Collapsed"
                                            IsTabStop="False"
                                            IsHitTestVisible="False"
                                            Content="{TemplateBinding Watermark}"
                                            Foreground="{StaticResource WatermarkBrush}"
                                            Background="{TemplateBinding Background}"
                                            FontFamily="{TemplateBinding FontFamily}"
                                            FontSize="{TemplateBinding FontSize}"
                                            FontStretch="{TemplateBinding FontStretch}"
                                            FontStyle="italic"
                                            FontWeight="{TemplateBinding FontWeight}"
                                            Padding="{TemplateBinding Padding}"
                                            />
                            </Grid>
                        </Microsoft_Windows_Themes:ListBoxChrome>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>
                            
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="Text" Value="" />
                                    <Condition Property="IsFocused" Value="false" />
                                    <Condition Property="IsEnabled" Value="true" />
                                </MultiTrigger.Conditions>
                                <Setter TargetName="PART_HelpTextElement" Property="Visibility" Value="Visible"/>
                            </MultiTrigger>

                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="Text" Value="{x:Null}" />
                                    <Condition Property="IsFocused" Value="false" />
                                    <Condition Property="IsEnabled" Value="true" />
                                </MultiTrigger.Conditions>
                                <Setter TargetName="PART_HelpTextElement" Property="Visibility" Value="Visible"/>
                            </MultiTrigger>
                            
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
            </Style>
        </TextBox.Style>
</TextBox>